/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package jp.co.irep.juten.facade;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.ParameterExpression;
import javax.persistence.criteria.Root;
import jp.co.irep.juten.entity.Template;

/**
 *
 * @author toan_nguyen
 */
@Stateless
public class TemplateFacade extends AbstractFacade<Template> {
    @PersistenceContext(unitName = "JutenPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public TemplateFacade() {
        super(Template.class);
    }
    
    @Override
    public List<Template> findAll(){
        CriteriaQuery query = getEntityManager().getCriteriaBuilder().createQuery();
        Root<Template> template = query.from(Template.class);
        query.select(template);
        query.orderBy(getEntityManager().getCriteriaBuilder().asc(template.get("id")));
        return getEntityManager().createQuery(query).getResultList();
    }
    
}
